<template>
  <div class="setting-theme">
    <div class="container">
      <div class="color-group group">
        <div class="group-title title">主题</div>
        <div class="theme-list">
          <div class="theme-list-item" v-for="theme in themes" :key="theme.value">
            <div
              class="theme-color"
              @click="handleChangeTheme(theme)"
              :style="{
                backgroundColor: theme.background,
                border: `2px solid var(--xz-secondbg)`
              }"
            ></div>
            <div class="theme-name">{{ theme.name }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
const themes = [
  {
    name: '默认',
    color: '#a0a0a0',
    background: '#ffffff',
    value: 'light'
  },
  {
    name: '深色',
    color: '#1b1c20',
    background: 'rgb(24, 26, 31)',
    value: 'dark'
  }
]

const handleChangeTheme = (themeObject: any) => {
  document.documentElement.setAttribute('data-theme', themeObject.value)
  localStorage.setItem('theme', themeObject.value)
  window.api.themeToggle(themeObject.value)
}
</script>

<style scoped lang="scss">
.setting-theme {
  width: 100%;
  height: 100%;
  background: var(--xz-card-bg);
  color: var(--xz-fontcolor);

  .container {
    padding: 20px;
    display: flex;
    flex-direction: column;

    .group {
      display: flex;
      flex-direction: column;

      .title {
        font-weight: bold;
        font-size: 16px;
        margin-bottom: 10px;
      }
    }
  }
}

.theme-list {
  display: flex;
  flex-wrap: wrap;
  gap: 15px;

  .theme-list-item {
    display: flex;
    flex-direction: column;
    align-items: center;

    .theme-color {
      width: 50px;
      height: 50px;
      border-radius: var(--xz-main-radius);
      background: var(--xz-card-bg);
      cursor: pointer;
    }

    .theme-name {
      font-size: 12px;
      margin-top: 5px;
      color: #a0a0a0;
    }
  }
}
</style>
